import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np

# 数据
labels = ["A", "B", "C", "D", "E"]
sizes = [15, 30, 45, 10, 5]

# 创建3D坐标轴
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")


# 创建饼状图
def func(pct, allvals):
    absolute = int(round(pct / 100.0 * np.sum(allvals)))
    return "{:.1f}% ({:d})".format(pct, absolute)


# 绘制饼状图
patches, texts, autotexts = ax.pie(
    sizes,
    labels=labels,
    autopct=lambda pct: func(pct, sizes),
    shadow=True,
    startangle=90,
)

# 设置标题和轴标签
ax.set_title("3D Pie Chart")
ax.set_xlabel("X Label")
ax.set_ylabel("Y Label")
ax.set_zlabel("Z Label")

# 隐藏坐标轴
ax.set_axis_off()

# 显示图形
plt.show()
